home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11068 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  61 lines

  1. Path: news.nrlssc.navy.mil!proteus!jacobs
  2. From: jacobs@proteus (Gregg A. Jacobs (X4720))
  3. Newsgroups: comp.lang.c++
  4. Subject: C++ calling Fortran
  5. Date: 12 Mar 1996 15:58:51 GMT
  6. Organization: Naval Research Laboratory, Stennis Space Center
  7. Message-ID: <4i46vr$njn@filet.nrlssc.navy.mil>
  8. NNTP-Posting-Host: proteus.nrlssc.navy.mil
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. I want a C++ program to call a subroutine written in fortran.
  12.  
  13. If the fortran subroutine is:
  14.  
  15.       subroutine foo(a)
  16.       real a
  17.       return
  18.       end
  19.  
  20. Then f77 generates an object file with a subroutine name of:
  21.  
  22. _foo_
  23.  
  24. A C (or C++) routine calling this would be:
  25.  
  26. void foo_(float *a);
  27.  
  28. main() {
  29.  
  30.    float a;
  31.    foo_(&a);
  32. }
  33.  
  34. The gcc compiler then generates an object file which looks for
  35. the name:
  36. _foo_
  37. This is fine, and the C program calls the fortran subroutine
  38.  
  39. However, g++ generates an object file which looks for the name:
  40. _foo___FPf
  41. The linker can not find this, so the C++ code will not call
  42. the fortran subroutine.
  43.  
  44.  
  45. --
  46. ========================================
  47. ===  Gregg Jacobs                    ===
  48. ===  Naval Research Lab              ===
  49. ===  Stennis Space Center, MS 39529  ===
  50. ===                                  ===
  51. ===  Building 1007 room 48           ===
  52. ========================================
  53. ===  jacobs@nrlssc.navy.mil          ===
  54. ===  phone: (601) 688-4720           ===
  55. ===  FAX:   (601) 688-4759           ===
  56. ========================================
  57. ===  "The reason for time is so      ===
  58. ===  that everything does not        ===
  59. ===  happen at once." -- BB          ===
  60. ========================================
  61.